<?php
namespace Mapi\Controller\V2_0;
use Mapi\Controller\BaseController;
class UserController extends BaseController
{

	public function isFrist()
	{
		$openid = I('post.weixinid');
		//var_dump($_POST);
		if(strlen($openid)<10){
			$this->apiReturn(0,'','weixinid error');
		}
		$map['weixinid'] = $openid;
		$rs = D('UserFrist')->where($map)->find();
		if($rs){
			$rers = 0;
		} else {
			$data['weixinid']=$openid;
			$data['c_time']=CURRENT_TIME;
			$rers = D('UserFrist')->add($data);
		}
		$this->apiReturn(1,$rers,'error');

	}

	public function getzhiqing()
	{

		//var_dump($_GET,$_POST,$_REQUEST);
		$school_id = I('post.school_id');
		$mldm = I('post.mldm');
		$yjxkdm = I('post.yjxkdm');
		$zymc = I('post.zymc');		
		$data_time =date('Y',CURRENT_TIME);


		if(intval($school_id)<10){
			$this->apiReturn(0,'','school_id error');
		}
		if(strlen($mldm)<2){
			$this->apiReturn(0,'','mldm error');
		}
		if(strlen($yjxkdm)<4){
			$this->apiReturn(0,'','yjxkdm error');
		}
		if(strlen($zymc)<3){
			$this->apiReturn(0,'','zymc error');
		}
	
		$map['school_id'] = $school_id;
		$map['data_time'] = $data_time;
		$map['mldm'] = $mldm;
		$map['yjxkdm'] = $yjxkdm;
		$map['zymc'] = $zymc;
		$map['data_time'] = $data_time;
		$rs = D('StudScoreZq')->where($map)->limit(3)->select();
		if($rs){
			$this->apiReturn(1,$rs,'ok');

		}
		$this->apiReturn(0,$list,'error');


	}


	public function  Setzhiqing()
	{
		$openid = I('post.weixinid');
		$nickname = I('post.nickname');

		$school_id = I('post.school_id');
		$mldm = I('post.mldm');
		$yjxkdm = I('post.yjxkdm');
		$zymc = I('post.zymc');
		$total = I('post.total');
		$xxfs = I('post.xxfs');
		if(strlen($openid)<10){
			$this->apiReturn(0,'','weixinid error');
		}
		if(strlen($nickname)<1){
			$this->apiReturn(0,'','nickname error');
		}
		if(intval($school_id)<10){
			$this->apiReturn(0,'','school_id error');
		}
		if(strlen($mldm)<2){
			$this->apiReturn(0,'','mldm error');
		}
		if(strlen($yjxkdm)<4){
			$this->apiReturn(0,'','yjxkdm error');
		}
		if(strlen($zymc)<3){
			$this->apiReturn(0,'','zymc error');
		}
		if(strlen($total)<3){
			$this->apiReturn(0,'','total error');
		}
	
		$val['school_id'] =$school_id;
		$val['mldm'] =$mldm;
		$val['yjxkdm'] =$yjxkdm;
		$val['zymc'] =$zymc;
		$val['total'] =$total;
		$val['data_time'] =date('Y',CURRENT_TIME);
		$val['c_time'] =CURRENT_TIME;
		$val['xxfs'] =$xxfs;
		$val['weixinid'] =$openid;
		$val['nickname'] =$nickname;




		$sql = "insert into chsi_stud_score_zy(weixinid,nickname,school_id,mldm,yjxkdm,zymc,total,data_time,c_time,xxfs) ";
		$sql .="value('".$val['weixinid']."'";
		$sql .=",'".$val['nickname']."'";
		$sql .=",'".$val['school_id']."'";
		$sql .=",'".$val['mldm']."'";
		$sql .=",'".$val['yjxkdm']."'";
		$sql .=",'".$val['zymc']."'";
		$sql .=",'".$val['total']."'";
		$sql .=",'".$val['data_time']."'";
		$sql .=",'".$val['c_time']."'";
		$sql .=",'".$val['xxfs']."'";

		$sql .=")";
		$sql .="on duplicate key update  ";
		$sql .="school_id=".$val['school_id'];
		$sql .=",nickname='".$val['nickname']."'";
		$sql .=",mldm='".$val['mldm']."'";
		$sql .=",yjxkdm='".$val['yjxkdm']."'";
		$sql .=",zymc='".$val['zymc']."'";
		$sql .=",total='".$val['total']."'";
		$sql .=",xxfs='".$val['xxfs']."'";

		$rs = D('StudScore')->execute($sql);
		if($rs){
			$this->apiReturn(1,$list,'ok');

		}
		$this->apiReturn(0,$list,'error');

	}
	//自己报考专业排名
	public function getAllList()
	{
		$openid = I('post.weixinid');
		$ordertype = I('post.ordertype');

		//$openid =1;
		$map['data_time'] = date('Y',CURRENT_TIME);
		$map['weixinid'] = $openid;
		$info =  D('StudScore')->where($map)->find();
		if($info){
			$sc = D('School')->where(['sccode'=>$info['school_id']])->find();
			$info['school_name'] =$sc['scname'] ;
			$sc = D('School')->where(['sccode'=>$info['school_id']])->find();
			if($info['mldm']=='zyxw'){
				$mldm_name="专业学位";
			} else {
				$mldm=json_decode($this->_menu['mldm'],true);
				foreach($mldm as $key=>$val){
					if($val['dm']==$info['mldm']){
						$mldm_name=$val['mc'];
						break;
					}
				}

			}
			$info['mldm_name'] = $mldm_name;
			$yjxkdm_name = D('major')->where(['dm'=>$info['yjxkdm']])->find();

			
			$info['yjxkdm_name'] =$yjxkdm_name['mc'] ;

			$info['class_name'][0] = "政治" ;
			$info['class_name'][1] = "英语";
			if(!D('Noshuxue')->kaoshuxue($info['zymc'])){
				$info['class_name'][2]= "数学";
			}else {
				$info['class_name'][2] = "专业一";
			}

			$info['class_name'][3] = "专业二";
			$info['class_name'][4] = "专业其他";

			//$where['school_id'] = $info['school_id'];
			$where['mldm'] = $info['mldm'];
			$where['yjxkdm'] = $info['yjxkdm'];
			$where['zymc'] = $info['zymc'];

			$infolist = D('StudScore')->where($where)->order('total desc')->limit(10)->select();

			if($infolist){
				$i=1;
				foreach($infolist as $key=>$val){
					$infolist[$key]['order'] =$i;
					$infolist[$key]['mldm_name'] =$mldm_name;
					$infolist[$key]['school_name'] =$info['school_name'];
					$infolist[$key]['yjxkdm_name'] =$yjxkdm_name['mc'] ;
					$infolist[$key]['class1_name'] = "政治" ;
					$infolist[$key]['class2_name'] = "英语";
					if(!D('Noshuxue')->kaoshuxue($info['zymc'])){
						$infolist[$key]['class3_name']= "数学";
					}else {
						$infolist[$key]['class3_name'] = "专业一";
					}

					$infolist[$key]['class4_name'] = "专业二";
					$infolist[$key]['class5_name'] = "专业其他";
					$i++;

				}
				$redata['zypm'] = $infolist;
	
			}
			$where=array();
			$where['school_id'] = $info['school_id'];
			$where['mldm'] = $info['mldm'];
			$where['yjxkdm'] = $info['yjxkdm'];
			$where['zymc'] = $info['zymc'];

			$infolist = D('StudScore')->where($where)->order('total desc')->limit(10)->select();
			if($infolist){
				$i=1;
				foreach($infolist as $key=>$val){
					$infolist[$key]['order'] =$i;
					$infolist[$key]['mldm_name'] =$mldm_name;
					$infolist[$key]['school_name'] =$info['school_name'];
					$infolist[$key]['yjxkdm_name'] =$yjxkdm_name['mc'] ;
					$infolist[$key]['class1_name'] = "政治" ;
					$infolist[$key]['class2_name'] = "英语";
					if(!D('Noshuxue')->kaoshuxue($info['zymc'])){
						$infolist[$key]['class3_name']= "数学";
					}else {
						$infolist[$key]['class3_name'] = "专业一";
					}


					$infolist[$key]['class4_name'] = "专业二";
					$infolist[$key]['class5_name'] = "专业其他";
					$i++;
				}
				$redata['xkpam'] = $infolist;

			}

			$redata['classname']=$info['class_name'];
			$this->apiReturn(1,$redata,'ok');

		} else {
			$this->apiReturn(0,'','error');
		}

	}
	//分享过
	public function getShareList()
	{
	
		$rs=D('UserWeixin')->limit(3)->order('c_time desc')->select();

		if($rs){
			$this->apiReturn(1,$rs,'ok');

		} else {
			$this->apiReturn(0,$rs,'error');

		}
	}

	//添加分享
	public function setShare()
	{
		$openid = I('post.weixinid');
		$nickname = I('post.nickname');
		$head = I('post.head');
		if(strlen($openid)<10){
			$this->apiReturn(0,'','weixinid error');
		}

		$nickname = "default";
		if(strlen($nickname)<2){
			//$this->apiReturn(0,'','nickname error');
		}
		$head="####";
		if(strlen($head)<3){
			$this->apiReturn(0,'','head error');
		}

		$data['weixinid']=$openid;
		$data['nickname']=$nickname;
		$data['head']=$head;
		$data['is_share']=1;
		$data['c_time']=CURRENT_TIME;

		$sql = "insert into chsi_user_weixin(weixinid,nickname,head,is_share,c_time) ";
		$sql .="value('".$data['weixinid']."','".$data['nickname']."','".$data['head']."','".$data['is_share']."',".$data['c_time'].") ";
		$sql .="on duplicate key update  ";
		$sql .="nickname= '".$data['nickname']."'";
		$sql .=",head= '".$data['head']."'";
		$rs=D('UserWeixin')->execute($sql);

		if($rs){
			$this->apiReturn(1,'','ok');

		} else {
			$this->apiReturn(0,'','error');

		}
	}

	//是或否分享过
	public function getShare()
	{
		$openid = I('post.weixinid');
		if(strlen($openid)<10){
			$this->apiReturn(0,'','weixinid error');
		}

		$data['weixinid']=$openid;
		$rs=D('UserWeixin')->where($data)->find();
		if($rs){
			$this->apiReturn(1,'','ok');

		} else {
			$this->apiReturn(0,'','error');

		}
	}
	//得到自己分数
	public function getMyScore()
	{
		$openid = I('post.weixinid');
		//$openid =1;
		if(strlen($openid)<10){
			$this->apiReturn(0,'','weixinid error');
		}

		$map['data_time'] = date('Y',CURRENT_TIME);
		$map['weixinid'] = $openid;
		$info =  D('StudScore')->where($map)->find();
		if($info){
			$sc = D('School')->where(['sccode'=>$info['school_id']])->find();
			$info['school_name'] =$sc['scname'] ;
			//$sc = D('School')->where(['sccode'=>$info['school_id']])->find();
			if($info['mldm']=='zyxw'){
				$mldm_name="专业学位";
			} else {
				$mldm=json_decode($this->_menu['mldm'],true);
				foreach($mldm as $key=>$val){
					if($val['dm']==$info['mldm']){
						$mldm_name=$val['mc'];
						break;
					}
				}

			}
			$info['mldm_name'] = $mldm_name;
			$yjxkdm_name = D('major')->where(['dm'=>$info['yjxkdm']])->find();

		
			$info['yjxkdm_name'] =$yjxkdm_name['mc'] ;

			$info['score'][0]['class'] =$info['class1'];
			$info['score'][1]['class'] =$info['class2'];
			$info['score'][2]['class'] =$info['class3'];
			$info['score'][3]['class'] =$info['class4'];
			$info['score'][4]['class'] =$info['class5'];
			$info['score'][0]['class_name'] = "政治" ;
			$info['score'][1]['class_name'] = "英语";
			if(!D('Noshuxue')->kaoshuxue($info['zymc'])){
				$info['score'][2]['class_name']= "数学";
			}else {
				$info['score'][2]['class_name'] = "专业一";
			}
			$info['score'][3]['class_name'] = "专业二";
			$info['score'][4]['class_name'] = "专业其他";
			$info['scoretype'] = $scoretype;
			$rs = $this->_mkorder($info);
			$info['order'] =$rs ;

			$this->apiReturn(1,$info,'ok');
		}
		$this->apiReturn(0,'','没有数据');
	}

	public function getOpenid()
	{

		$authorization_code = I('post.authorizationCode');
		//$js_code = I('post.jscode');
		if(strlen($authorization_code)<10){
			$this->apiReturn(0,'','authorization_code error');
		}

		$APPID="wxcddfdcc6fce02a80";
		$SECRET="672973cb474327a8b9a16d4461ded3f2";
		//$authorization_code="021pjlHJ0fmEc82RShFJ0EUpHJ0pjlHl";
		$url = "https://api.weixin.qq.com/sns/jscode2session?appid=".$APPID;
		$url .= "&secret=".$SECRET;
		$url .= "&js_code=".$authorization_code;
		$url .= "&grant_type=authorization_code";
		$rs = $this->curl_post($url,"");

		//var_dump($rs,$url);

		//$rs = '{"openid": "OPENID","session_key": "SESSIONKEY"}';
		$info  = json_decode($rs,true);

		if($info['errcode']){
			$this->apiReturn(0,'','没有数据');
		} else {
			$this->apiReturn(1,$info,'ok');
		}

	}

	/*
	 * 保存成绩
	 * */
	public function saveScore()
	{
		$weixinid = I('post.weixinid');
		$school_id = I('post.school_id');
		$mldm = I('post.mldm');
		$yjxkdm = I('post.yjxkdm');
		$zymc = I('post.zymc');
		$class1 = I('post.class1');
		$class2 = I('post.class2');
		$class3 = I('post.class3');
		$class4 = I('post.class4');
		$class5 = I('post.class5');
		$xxfs = I('post.xxfs');

		if(strlen($weixinid)<10){
			$this->apiReturn(0,'','weixinid error');
		}
		if(intval($school_id)<10){
			$this->apiReturn(0,'','school_id error');
		}
		if(strlen($mldm)<2){
			$this->apiReturn(0,'','mldm error');
		}
		if(strlen($yjxkdm)<4){
			$this->apiReturn(0,'','yjxkdm error');
		}
		if(strlen($zymc)<3){
			$this->apiReturn(0,'','zymc error');
		}
		if(intval($class1)<0){
			$this->apiReturn(0,'','class1 error');
		}
		if(intval($class2)<0){
			$this->apiReturn(0,'','class2 error');
		}
		if(intval($class3)<0){
			$this->apiReturn(0,'','class3 error');
		}
		if(intval($class4)<0){
			$this->apiReturn(0,'','class4 error');
		}
		if(intval($class5)<0){
			$this->apiReturn(0,'','class5 error');
		}
		if(intval($xxfs)<0){
			$this->apiReturn(0,'','class5 error');
		}
		/*

		$weixinid = "333";
		$school_id = "10001";
		$mldm ="01";
		$yjxkdm = "0101";
		$zymc = "中国哲学";
		$class1 = 99;
		$class2 = 100;
		$class3 = 122;
		$class4 = 133;
		$class5 =66;
		*/
		$data_time = date('Y',CURRENT_TIME);
		$c_time = CURRENT_TIME;

		$val['weixinid']=$weixinid;
		$val['school_id']=$school_id;
		$val['mldm']=$mldm;
		$val['yjxkdm']=$yjxkdm;
		$val['zymc']=$zymc;
		$val['class1']=$class1;
		$val['class2']=$class2;
		$val['class3']=$class3;
		$val['class4']=$class4;
		$val['class5']=$class5;
		$val['data_time']=$data_time;
		$val['c_time']=$c_time;
		$val['xxfs']=$xxfs;
		$val['total']=$class1+$class2+$class3+$class4+$class5;


		$sql = "insert into chsi_stud_score(weixinid,school_id,mldm,yjxkdm,zymc,class1,class2,class3,class4,class5,total,data_time,c_time,xxfs) ";
		$sql .="value('".$val['weixinid']."'";
		$sql .=",'".$val['school_id']."'";
		$sql .=",'".$val['mldm']."'";
		$sql .=",'".$val['yjxkdm']."'";
		$sql .=",'".$val['zymc']."'";
		$sql .=",'".$val['class1']."'";
		$sql .=",'".$val['class2']."'";
		$sql .=",'".$val['class3']."'";
		$sql .=",'".$val['class4']."'";
		$sql .=",'".$val['class5']."'";
		$sql .=",'".$val['total']."'";
		$sql .=",'".$val['data_time']."'";
		$sql .=",'".$val['c_time']."'";
		$sql .=",'".$val['xxfs']."'";
		$sql .=")";
		$sql .="on duplicate key update  ";
		$sql .="school_id='".$val['school_id']."'";
		$sql .=",mldm='".$val['mldm']."'";
		$sql .=",yjxkdm='".$val['yjxkdm']."'";
		$sql .=",zymc='".$val['zymc']."'";
		$sql .=",class1=".$val['class1'];
		$sql .=",class2=".$val['class2'];
		$sql .=",class3=".$val['class3'];
		$sql .=",class4=".$val['class4'];
		$sql .=",class5=".$val['class5'];
		$sql .=",total=".$val['total'];
		$sql .=",xxfs=".$val['xxfs'];
		$rs = D('StudScore')->execute($sql);
		if($rs){
			$this->apiReturn(1,$list,'ok');

		}
		$this->apiReturn(0,$list,'error');

	}

	public function getMyorder(){

		$weixinid = I('post.weixinid');
		$scoretype = I('post.scoretype');
		$school_id = I('post.school_id');
		$mldm = I('post.mldm');
		$yjxkdm = I('post.yjxkdm');
		$zymc = I('post.zymc');
		$class1 = I('post.class1');
		$class2 = I('post.class2');
		$class3 = I('post.class3');
		$class4 = I('post.class4');
		$class5 = I('post.class5');
		$scoretype = I('post.scoretype');
		/*
		$weixinid = "100000000000000";
		$school_id = "10001";
		$mldm ="zyxw";
		$yjxkdm = "0852";
		$zymc = "化学工程";
		$class1 = 99;
		$class2 = 100;
		$class3 = 122;
		$class4 = 133;
		$class5 =66;
		$scoretype =2;
		*/

		if(strlen($weixinid)<10){
			$this->apiReturn(0,'','weixinid error');
		}
		if(intval($school_id)<10){
			$this->apiReturn(0,'','school_id error');
		}
		if(strlen($mldm)<2){
			$this->apiReturn(0,'','mldm error');
		}
		if(strlen($yjxkdm)<4){
			$this->apiReturn(0,'','yjxkdm error');
		}
		if(strlen($zymc)<3){
			$this->apiReturn(0,'','zymc error');
		}
		if(intval($class1)<0){
			$this->apiReturn(0,'','class1 error');
		}
		if(intval($class2)<0){
			$this->apiReturn(0,'','class2 error');
		}
		if(intval($class3)<0){
			$this->apiReturn(0,'','class3 error');
		}
		if(intval($class4)<0){
			$this->apiReturn(0,'','class4 error');
		}
		if(intval($class5)<0){
			$this->apiReturn(0,'','class5 error');
		}
		if(intval($xxfs)<0){
			$this->apiReturn(0,'','class5 error');
		}
		if(intval($scoretype)<1){
			$this->apiReturn(0,'','scoretype error');
		}
		if($scoretype == 1) {

			$map['data_time'] = date('Y',CURRENT_TIME);
			$map['weixinid'] = $weixinid;
			$info = D('StudScore')->where($map)->find();
			//echo D('StudScore')->getlastsql();
			if(!$info)
			{
				$this->apiReturn(0,$list,'请填写成绩');
			}
			$info['score'][0]['class'] =$info['class1'];
			$info['score'][1]['class'] =$info['class2'];
			$info['score'][2]['class'] =$info['class3'];
			$info['score'][3]['class'] =$info['class4'];
			$info['score'][4]['class'] =$info['class5'];
			$info['score'][0]['class_name'] = "政治" ;
			$info['score'][1]['class_name'] = "英语";
			if(!D('Noshuxue')->kaoshuxue($zymc)){
				$info['score'][2]['class_name']= "数学";
			}else {
				$info['score'][2]['class_name'] = "专业一";
			}

			$info['score'][3]['class_name'] = "专业二";
			$info['score'][4]['class_name'] = "专业其他";

		} else{
			$data_time = date('Y',CURRENT_TIME);
			$c_time = CURRENT_TIME;

			$info['weixinid']=$weixinid;
			$info['school_id']=$school_id;
			$info['mldm']=$mldm;
			$info['yjxkdm']=$yjxkdm;
			$info['zymc']=$zymc;
			$info['class1']=$class1;
			$info['class2']=$class2;
			$info['class3']=$class3;
			$info['class4']=$class4;
			$info['class5']=$class5;
			$info['data_time']=$data_time;
			$info['c_time']=$c_time;
			$info['total']=$class1+$class2+$class3+$class4+$class5;
			$info['score'][0]['class'] =$info['class1'];
			$info['score'][1]['class'] =$info['class2'];
			$info['score'][2]['class'] =$info['class3'];
			$info['score'][3]['class'] =$info['class4'];
			$info['score'][4]['class'] =$info['class5'];
			$info['score'][0]['class_name'] = "政治" ;
			$info['score'][1]['class_name'] = "英语";
			if(!D('Noshuxue')->kaoshuxue($zymc)){
				$info['score'][2]['class_name']= "数学";
			}else {
				$info['score'][2]['class_name'] = "专业一";
			}

			$info['score'][3]['class_name'] = "专业二";
			$info['score'][4]['class_name'] = "专业其他";


		}
		$info['scoretype'] = $scoretype;

		$rs = $this->_mkorder($info);

		$this->apiReturn(1,$rs,'ok');









	}

	// 排名
	private function _mkorder($score)
	{

		$where['school_id']=$score['school_id'];
		$where['mldm']=$score['mldm'];
		$where['yjxkdm']=$score['yjxkdm'];
		$where['data_time']=date('Y',CURRENT_TIME);
		$info=array();
		$yjxkdm =  D('StudScore')->where($where)->select();

		//var_dump($yjxkdm ); exit;
		if(!$yjxkdm){
			$info['school'] =$score;
			$info['school']['orderclass1']=1;
			$info['school']['orderclass2']=1;
			$info['school']['orderclass3']=1;
			$info['school']['orderclass4']=1;
			$info['school']['orderclass5']=1;
			$info['school']['ordertotal']=1;
			$info['school']['ordertotalpre']=1;
			$info['school']['totalpeo'] =1;


		} else {
			$info['school']=$this->_mkorderinfo($yjxkdm,$score);
			$info['school']['totalpeo'] =count($yjxkdm);

		}
		$info['school']['score'][0]['order'] = $info['school']['orderclass1'];
		$info['school']['score'][1]['order'] = $info['school']['orderclass2'];
		$info['school']['score'][2]['order'] = $info['school']['orderclass3'];
		$info['school']['score'][3]['order'] = $info['school']['orderclass4'];
		$info['school']['score'][4]['order'] = $info['school']['orderclass5'];

		$map['dm'] = $score['yjxkdm'];
		$nameinfo= D('major')->where($map)->find();
		$info['school']['showname']=$nameinfo['mc'];

		if($score['mldm'] == 'zyxw'){
			$map =array();
			$map['mldm'] = 'zyxw';
			$map['zymc'] = $score['zymc'];
			$tt  = D('ZyMenu')->where($map)->find();
			$type = $tt['yjxkdm'];
		} else {
			$type=$score['mldm'];

		}

		$info['school']['line'] = $this->_line($info['school'],$type,$score);

		$where =array();
		//$where['school_id']=$score['school_id'];
		$where['mldm']=$score['mldm'];
		$where['yjxkdm']=$score['yjxkdm'];
		$where['data_time']=date('Y',CURRENT_TIME);

		$where['zymc']=$score['zymc'];
		$zymc =  D('StudScore')->where($where)->select();
		//var_dump($zymc ); exit;

		if(!$zymc){
			$info['country'] =$score;
			$info['country']['orderclass1']=1;
			$info['country']['orderclass2']=1;
			$info['country']['orderclass3']=1;
			$info['country']['orderclass4']=1;
			$info['country']['orderclass5']=1;
			$info['country']['ordertotal']=1;
			$info['country']['ordertotalpre']=1;
			$info['country']['totalpeo'] =1;

		} else {
			$info['country']=$this->_mkorderinfo($zymc,$score);
			$info['country']['totalpeo'] =count($zymc);

		}
		$info['country']['score'][0]['order'] = $info['country']['orderclass1'];
		$info['country']['score'][1]['order'] = $info['country']['orderclass2'];
		$info['country']['score'][2]['order'] = $info['country']['orderclass3'];
		$info['country']['score'][3]['order'] = $info['country']['orderclass4'];
		$info['country']['score'][4]['order'] = $info['country']['orderclass5'];

		$scinfo = D('School')->where(['sccode'=>$score['school_id']])->find();
		$info['country']['scname']=$scinfo['scname'];
		$info['country']['showname']=$score['zymc'];

		if($score['mldm'] == 'zyxw'){
			$map =array();
			$map['mldm'] = 'zyxw';
			$map['zymc'] = $score['zymc'];
			$tt  = D('ZyMenu')->where($map)->find();
			$type = $tt['yjxkdm'];
		} else {
			$type=$score['mldm'];

		}
		$info['country']['line'] = $this->_line($info['country'],$type,$score);

		return $info;

	
	}
	private function _line($data,$type,$score)
	{
		//var_dump($type); exit;
		$map['mldm']=$type;
		$map['type']=1;
		$line = D('Line')->where($map)->order('year asc')->select();
		$map['type']=2;
		$line2 = D('Line')->where($map)->order('year asc')->select();

		/*
		if($type=='zymc'){
			$line = "";
		} else {
			$line = "";
		}
		$line =array();
		for($i=2014;$i<2019;$i++){
			$line[$i] = rand(400,600);
		}
		*/

		$Year = Date('Y',CURRENT_TIME);
		$Year = intval($Year)-1;
		$lastyearfen = $line[count($line)-1]['fen'];
		if($lastyearfen >$data['total']){
			$redata['word'] = "小于";
		}
		if($lastyearfen ==$data['total']){
			$redata['word'] = "等于";
		}
		if($lastyearfen <$data['total']){
			$redata['word'] = "大于";
		}

		$redata['lastyearfen'] =abs($data['total']-$lastyearfen);
		$i=0;
		foreach($line as $key=>$val){
			$years[$i] = $val['year'];
			$A[$i] = $val['fen'];
			$B[$i] = $line2[$key]['fen'];
			$i++;

		}
		$redata['line']['yeararr'] = $years;
		$redata['line']['A'] = $A;

		$redata['line']['B'] = $B;

		return $redata;
	}

	private function _mkorderinfo($yjxkdm,$score)
	{
		if($score['scoretype']==2){
			$yjxkdm[count($yjxkdm)] = $score;
		}
		$totalpeo=count($yjxkdm);
		$type=2; //1 排名 2 百分比

		if($type==1){

			$score['orderclass1']=$this->_getrank($yjxkdm,'class1',$score['weixinid']);
			$score['orderclass2']=$this->_getrank($yjxkdm,'class2',$score['weixinid']);
			$score['orderclass3']=$this->_getrank($yjxkdm,'class3',$score['weixinid']);
			$score['orderclass4']=$this->_getrank($yjxkdm,'class4',$score['weixinid']);
			$score['orderclass5']=$this->_getrank($yjxkdm,'class5',$score['weixinid']);
			$score['ordertotal']=$this->_getrank($yjxkdm,'total',$score['weixinid']);
			$pre= 100-intval(($this->_getrank($yjxkdm,'total',$score['weixinid'])/$totalpeo)*100);
			$score['ordertotalpre']= $pre== 0 ? 1 : $pre;
		} else {

			$score['orderclass1']=$this->_getrank($yjxkdm,'class1',$score['weixinid']);
			$score['orderclass2']=$this->_getrank($yjxkdm,'class2',$score['weixinid']);
			$score['orderclass3']=$this->_getrank($yjxkdm,'class3',$score['weixinid']);
			$score['orderclass4']=$this->_getrank($yjxkdm,'class4',$score['weixinid']);
			$score['orderclass5']=$this->_getrank($yjxkdm,'class5',$score['weixinid']);


			$score['orderclass1']=100-intval(($score['orderclass1']/$totalpeo)*100);
			$score['orderclass2']=100-intval(($score['orderclass2']/$totalpeo)*100);
			$score['orderclass3']=100-intval(($score['orderclass3']/$totalpeo)*100);
			$score['orderclass4']=100-intval(($score['orderclass4']/$totalpeo)*100);
			$score['orderclass5']=100-intval(($score['orderclass5']/$totalpeo)*100);
			$score['orderclass1']= $score['orderclass1']== 0 ? 1 : $score['orderclass1'];
			$score['orderclass2']= $score['orderclass2']== 0 ? 1 : $score['orderclass2'];
			$score['orderclass3']= $score['orderclass3']== 0 ? 1 : $score['orderclass3'];
			$score['orderclass4']= $score['orderclass4']== 0 ? 1 : $score['orderclass4'];
			$score['orderclass5']= $score['orderclass5']== 0 ? 1 : $score['orderclass5'];

			$score['orderclass1'].="%";
			$score['orderclass2'].="%";
			$score['orderclass3'].="%";
			$score['orderclass4'].="%";
			$score['orderclass5'].="%";

			$score['ordertotal']=$this->_getrank($yjxkdm,'total',$score['weixinid']);
			$pre= 100-intval(($this->_getrank($yjxkdm,'total',$score['weixinid'])/$totalpeo)*100);
			$score['ordertotalpre']= $pre== 0 ? 1 : $pre;

		}

		return $score;

	}

	private function _getrank($yjxkdm,$key,$weixinid)
	{

		$last_names = array_column($yjxkdm,$key);
		array_multisort($last_names,SORT_DESC,$yjxkdm);
		$i=1;
		//var_dump($yjxkdm); exit;
		foreach($yjxkdm as $key=>$val){
			if($val['weixinid'] == $weixinid){
				return $i;
			}
			$i++;
		}

	}

	private function curl_post($url,$post_data)
	{
		//初始化
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
		curl_setopt($ch, CURLOPT_HEADER, 0);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_data));
		curl_setopt($ch, CURLOPT_TIMEOUT, 5);
		$resultJson = curl_exec($ch);
		$curlInfo = curl_getinfo($ch);
		$errNo = curl_errno($ch);
		curl_close($ch);
		//显示获得的数据
		return $resultJson;
	}	


}